package com.heima.article.listener;

import com.heima.article.service.ApArticleConfigService;
import com.heima.common.constants.MQConstants;
import com.heima.utils.common.JsonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 文章上下架监听器
 */
@Component
@Slf4j
public class ArticleDownOrUpListener {
    @Autowired
    private ApArticleConfigService apArticleConfigService;

    @KafkaListener(topics = MQConstants.WM_NEWS_UP_OR_DOWN_TOPIC)
    public void handleDownOrUp(String msg){
        log.info("文章上下架请求接受成功，消息内容：{}",msg);
        Map msgMap = JsonUtils.toBean(msg, Map.class);
        apArticleConfigService.downOrUp(msgMap);
    }
}
